package com.ch.forum.dao;

import com.ch.forum.model.UserModel;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface UserMapper {

    @Insert("insert into t_user(date,is_valid,level,nick_name,phone,pwd,img_url,point,p_id,multiple,deal_pwd)" +
            "values(#{date},#{isValid},#{level},#{nickName},#{phone},#{pwd},#{imgUrl},#{point},#{pId},#{multiple},#{dealPwd})")
    int addUser(UserModel userModel);

    @Select("select id,date,is_valid as isValid,level,nick_name as nickName,phone,pwd,real_name as realName,integral,img_url as imgUrl,deal_pwd as dealPwd,p_id as pId from t_user where phone = #{phone}")
    UserModel findByPhone(@Param("phone") String phone);

    @Select("select id,date,is_valid as isValid,level,nick_name as nickName,phone,pwd,real_name as realName,integral,img_url as imgUrl,point,virtual_point as virtualPoint,deal_pwd as dealPwd from t_user where id = #{id}")
    UserModel findById(@Param("id")Long id);

    @Select("select id,date,is_valid as isValid,level,nick_name as nickName,phone,pwd,real_name as realName from t_user " +
            "where is_valid = 0 limit #{pageNum},#{pageSize}")
    List<UserModel> checkListPage(@Param("pageNum") int pageNum,@Param("pageSize") int pageSize);

    @Select("select count(1) from t_user where is_valid = 0")
    int checkCount();

    @Update("update t_user set is_valid = 1 where id = #{id}")
    int checkUser(String id);

    @Update("update t_user set level = 1 where id in (#{ids})")
    int vipUser(String ids);

    @Update("update t_user set pwd = #{pwd} where phone = #{phone}")
    int updatePwd(@Param("pwd")String pwd, @Param("phone")String phone);

    @Update("update t_user set phone=#{phone},nick_name=#{nickName},img_url=#{imgUrl} where id = #{userId}")
    int updateUserInfo(@Param("phone")String phone, @Param("nickName")String nickName, @Param("imgUrl")String imgUrl, @Param("userId")Long userId);

    @Select("select is_valid from t_user where id = #{id}")
    int getValidByUserId(@Param("id")Long id);

    @Update("update t_user set point = #{point} where id = #{id}")
    int updatePoint(@Param("id")Long id, @Param("point")Double point);

    @Update("update t_user set virtual_point = #{point} where id = #{id}")
    int updateVirtualPoint(@Param("id")Long id, @Param("point")Double point);

    @Select("select t.p_id from t_user t where t.id = #{id}")
    Long findPidById(@Param("id")Long id);

    @Select("select t.id,t.nick_name,phone from t_user t")
    List<Map> findUserLists();
}
